<%--
XPTracker - Alternative Agile Tracking Tool
Copyright (C) 2006-2009  Stephen Starkey

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
--%>
<%@ include file="/taglibs.jsp" %>
<c:set var="title" value="Queues" scope="request"/>
<s:layout-render name="/layout/normal.jsp">
  <s:layout-component name="body">
    <dt:table name="actionBean.queues" id="queue" class="data">
      <dt:column title="Queue">
        <s:link id="queue-${queue.id}" beanclass="org.xptracker.web.PlanningActionBean">
          ${queue.name}
          <s:param name="src">${queue.id}</s:param>
        </s:link>
      </dt:column>
      <dt:column title="Type">
        <a href="#" name="queueType"
           onclick="changeQueueType(${queue.id}, '${queue.type == "priority" ? "severity" : "priority"}')">
           ${queue.type == 'priority' ? 'Priority' : 'Severity'}
        </a>
      </dt:column>
      <dt:column title="">
        <input type="button" name="openClose" value="${queue.open ? 'Close' : 'Open'}"
               onclick="${queue.open ? 'close' : 'open'}Queue(${queue.id});"/>
        <c:choose>
          <c:when test="${queue.deletable}">
            <input type="button" onclick="deleteQueue(${queue.id})" value="Delete"/>
          </c:when>
          <c:when test="${queue.hiddenPrimitive}">
            <input type="button" onclick="showQueue(${queue.id})" value="Show"/>
          </c:when>
          <c:otherwise>
            <input type="button" onclick="hideQueue(${queue.id})" value="Hide"/>
          </c:otherwise>
        </c:choose>
      </dt:column>
    </dt:table>
    <br/><input type="button" onclick="addQueue()" value="Add"/>

    <script type="text/javascript">
      function addQueue() {
        var queueName = prompt("Queue name");
        if (queueName) {
          $('queueName').value = queueName;
          $('addForm').submit();
        }
      }

      function deleteQueue(queueId) {
        var queueName = $('queue-' + queueId).innerHTML;
        if (confirm('Really delete queue "' + queueName + '"?')) {
          $('queueId').value = queueId;
          $('deleteForm').submit();
        }
      }

      function showQueue(queueId) {
        submitOpenClose('Show', queueId);
      }

      function hideQueue(queueId) {
        submitOpenClose('Hide', queueId);
      }

      function openQueue(queueId) {
        submitOpenClose('Open', queueId);
      }

      function closeQueue(queueId) {
        submitOpenClose('Close', queueId);
      }

      function submitOpenClose(event, queueId) {
        $('openOrClose').name = event;
        $('ocQueueId').value = queueId;
        $('openCloseForm').submit();
      }

      function changeQueueType(queueId, newType) {
        $('queueType').value = newType;
        $('qtQueueId').value = queueId;
        $('queueTypeForm').submit();
      }
    </script>

    <s:form id="addForm" beanclass="org.xptracker.web.QueuesActionBean" style="display:none">
      <input type="hidden" name="Add" value="1"/>
      <input type="hidden" id="queueName" name="queueName" value=""/>
    </s:form>
    <s:form id="deleteForm" beanclass="org.xptracker.web.QueuesActionBean" style="display:none">
      <input type="hidden" name="Delete" value="1"/>
      <input type="hidden" id="queueId" name="queueId" value=""/>
    </s:form>
    <s:form id="openCloseForm" beanclass="org.xptracker.web.QueuesActionBean" style="display:none">
      <input type="hidden" id="openOrClose" name="" value="1"/>
      <input type="hidden" id="ocQueueId" name="queueId" value=""/>
    </s:form>
    <s:form id="queueTypeForm" beanclass="org.xptracker.web.QueuesActionBean" style="display:none">
      <input type="hidden" name="ChangeType" value="1"/>
      <input type="hidden" id="qtQueueId" name="queueId" value=""/>
      <input type="hidden" id="queueType" name="queueType" value=""/>
    </s:form>
  </s:layout-component>
</s:layout-render>